package cn.jsj.dispose;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontLawyer;
import cn.jsj.pojo.TblLawyer;
import cn.jsj.temporary.data.TemporaryData;
import cn.jsj.utils.ProduceJsonData;
import cn.jsj.utils.SysLogger;
/**
 * 加载所有律师信息处理类
 * @author LI
 *
 */
public class LawyerInfoRequest extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("请求查看律师详细信息！！！");
		
		//获得参数：1.第几条开始。2.一页显示几条
		int startNumb=Integer.parseInt(request.getParameter("start"));
		int totalNumb=Integer.parseInt(request.getParameter("limit"));
		
		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("start---->"+startNumb+"   total--------->"+totalNumb);
		 
		
		
		//判断是否已经知道律师信息条数
		if(TemporaryData.getLawyerInfoSize()==0){
			
			//获得律师信息条数
			cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
			int lawyerNumber=tld.getLawyerInfoNumb();
			
			//存起来
			TemporaryData.setLawyerInfoSize(lawyerNumber);
		}
		
		//暂存律师信息队列
		java.util.List<TblLawyer> lawyerInfo=new java.util.LinkedList<TblLawyer>();
		
		//获取这个页面要显示的律师信息
		cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
		lawyerInfo=tld.getTheLawyerInfo(startNumb, totalNumb);
		
		//调试信息
		SysLogger.PrintInfo(lawyerInfo.size());
		
		//前台律师信息对象队列
		java.util.List<FrontLawyer> frontLawyerInfo=new java.util.LinkedList<FrontLawyer>();
		
		//改造成前台需要的律师信息对象
		cn.jsj.object.rebuild.LawyerInfoRebuild lir=new cn.jsj.object.rebuild.LawyerInfoRebuild();
		for(int i=0;i<lawyerInfo.size();i++){
			cn.jsj.object.FrontLawyer fl=lir.rebuildLawyer(lawyerInfo.get(i));
			frontLawyerInfo.add(fl);
		}

		//改造成JSON型数据
		ProduceJsonData pjd=new ProduceJsonData();
	String resultData=	pjd.jsonFromList(frontLawyerInfo,TemporaryData.getLawyerInfoSize());
		
	//调试信息
	SysLogger.PrintInfo(resultData);
	//输出到客户端
	java.io.PrintWriter pw=response.getWriter();
	pw.println(resultData);
	pw.flush();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request,response);
	}

}
